//
//  GKLHelpCenterCell.m
//  jinwan
//
//  Created by GKiOS on 2017/6/6.
//  Copyright © 2017年 wy. All rights reserved.
//

#import "GKLHelpCenterCell.h"

@interface GKLHelpCenterCell ()
@property(nonatomic, strong) UIView   *line;
@property(nonatomic, strong) UILabel   *contentLabel;
@end

@implementation GKLHelpCenterCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self.contentView addSubview:self.line];
        [self.contentView addSubview:self.contentLabel];
        [self createConstraints];
    }
    return self;
}

- (void)createConstraints
{
    [self.line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(12);
        make.right.equalTo(self.contentView).offset(-12);
        make.top.equalTo(self.contentView);
        make.height.equalTo(@0.5);
    }];
    CGFloat w = kScreenWidth - 12 * 2;
    [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.line.mas_left);
        make.top.equalTo(self.contentView.mas_top).offset(10);
        make.width.equalTo(@(w));
        make.bottom.equalTo(self.contentView.mas_bottom).offset(-10);
    }];
}

#pragma mark - setter

- (void)setModel:(GKLHelpCenterModel *)model
{
    _model = model;
    if ([_model.content isEqualToString:@""] || _model.content == nil) {
        _model.content = @"NULL";
    }
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:_model.content];
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    [paragraphStyle setLineSpacing:5];
    [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, _model.content.length)];
    self.contentLabel.attributedText = attributedString ;
}

#pragma mark - getter

- (UIView *)line
{
    if (_line == nil) {
        _line = [[UIView alloc] init];
        _line.backgroundColor = [UIColor custom_color:@"#EEEEEE"];
    }
    return _line;
}


- (UILabel *)contentLabel
{
    if (_contentLabel == nil) {
        _contentLabel = [[UILabel alloc] init];
        _contentLabel.font = [UIFont systemFontOfSize:12];
        _contentLabel.textColor = [UIColor custom_color:@"#AAAAAA"];
        _contentLabel.numberOfLines = 0;
        _contentLabel.preferredMaxLayoutWidth = kScreenWidth - 12*2;
//        _contentLabel.backgroundColor = [UIColor redColor];
    }
    return _contentLabel;
}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

@end
